package org.dromara.xxmj.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.xxmj.domain.CourseScore;
import org.dromara.xxmj.domain.dto.*;
import org.dromara.xxmj.domain.vo.*;
import org.dromara.xxmj.service.XxmjExercisesService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 习题控制器
 *
 * @author Lion Li
 */
@Slf4j
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/xxmj/question")
public class XxmjExercisesController extends BaseController {

    @Resource
    private XxmjExercisesService xxmjExercisesService;

    /**
     * 习题目录
     *
     * @Author 王晨沣
     * @Date 2025-05-20 15:55:30
     */
    @Operation(summary = "习题目录")
    @PostMapping("/list")
    public R<List<CourseGeneralVO>> list(@RequestBody @Valid GetQuestionListDTO getQuestionListDTO) {
        List<CourseGeneralVO> list = xxmjExercisesService.list(getQuestionListDTO);
        return R.ok(list);
    }

    /**
     * 错题本列表
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "获取错题本详情")
    @GetMapping("/getDetailList/{stuId}")
    public R<List<UserErrorQuestionInfoVO>> getDetailList(@Parameter(description = "学生ID") @PathVariable Long stuId) {
        List<UserErrorQuestionInfoVO> list = xxmjExercisesService.getDetailList(stuId);
        return R.ok(list);
    }

    /**
     * 错题本提交答案
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "提交错题答案")
    @PostMapping("/detailSubmit")
    public R<Boolean> detailSubmit(@RequestBody @Valid ExerciseSubmitDto dto) {
        xxmjExercisesService.detailSubmitAnswer(dto);
        return R.ok("提交成功");
    }

    /**
     * 删除错题
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "删除错题")
    @PostMapping("/delete/{id}")
    public R<Boolean> delete(@Parameter(description = "错题索引") @PathVariable Long id) {
        xxmjExercisesService.delete(id);
        return R.ok("删除成功");
    }

    /**
     * 收藏库列表
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "获取收藏库列表")
    @GetMapping("/getCollectList/{stuId}")
    public R<List<UserCollectQuestionInfoVO>> getCollectList(@Parameter(description = "学生ID") @PathVariable String stuId) {
        List<UserCollectQuestionInfoVO> list = xxmjExercisesService.getCollectList(stuId);
        return R.ok(list);
    }

    /**
     * 添加收藏库列表
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "添加收藏库列表")
    @PostMapping("/addCollect/{courseId}/{questionId}/{questionType}")
    public R<Boolean> addCollect(@Parameter(description = "课程ID") @PathVariable String courseId,
                                 @Parameter(description = "题目ID") @PathVariable Long questionId,
                                 @Parameter(description = "题目类型") @PathVariable Integer questionType) {
        xxmjExercisesService.addCollect(courseId, questionId, questionType);
        return R.ok("添加成功");
    }

    /**
     * 取消收藏
     * @Author 王晨沣
     * @Date 2025-05-21 16:23:29
     */
    @Operation(summary = "取消收藏")
    @PostMapping("/cancelCollect/{id}")
    public R<Boolean> cancelCollect(@Parameter(description = "收藏索引") @PathVariable Long id) {
        xxmjExercisesService.cancelCollect(id);
        return R.ok();
    }

    /**
     * 提交模拟卷答案
     * @Author 王晨沣
     * @Date 2025-05-22 14:20:41
     */
    @Operation(summary = "提交模拟卷答案")
    @PostMapping("/submitSimulation")
    public R<SubmitSimulationVO> submitSimulation(@RequestBody @Validated SimulationSubmitDTO dto) {
        return R.ok( xxmjExercisesService.submitSimulation(dto));
    }

    /**
     * 考试分数列表
     * @Author 王晨沣
     * @Date 2025-05-22 14:20:41
     */
    @Operation(summary = "考试分数列表")
    @GetMapping("/getScoreList")
    public R<List<CourseScore>> getScoreList() {
        List<CourseScore> list = xxmjExercisesService.getScoreList();
        return R.ok(list);
    }

    /**
     * 今日练习统计接口
     * @Author 王晨沣
     * @Date 2025-05-22 14:20:41
     */
    @Operation(summary = "今日练习统计接口")
    @GetMapping("/getTodayPractice")
    public R<GetTodayPracticeVO> getTodayPractice() {
        GetTodayPracticeVO vo = xxmjExercisesService.getTodayPractice();
        return R.ok(vo);
    }

    /**
     * 最近练习
     *
     * @Author 王晨沣
     * @Date 2025-05-22 14:20:41
     */
    @Operation(summary = "最近练习")
    @GetMapping("/getRecentPractice")
    public R<List<CoursePracticeVO>> getRecentPractice() {
        List<CoursePracticeVO> list = xxmjExercisesService.getRecentPractice();
        return R.ok(list);
    }



}
